package com.un10.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.un10.entity.Administrator;
import com.un10.service.AdminService;

@Controller
public class AdministratorController {
@Autowired
  AdminService adminService;	
	//锟矫伙拷锟斤拷录
	@RequestMapping("/houtai/login")
public String login(Administrator admin,Model model, HttpSession session) {
	//锟斤拷锟斤拷锟矫伙拷锟剿猴拷锟斤拷锟斤拷锟斤拷
	String accountNum =admin.getAccountNum();	
	String  thecode=admin.getThecode();
	System.out.println(accountNum);
	System.out.println(thecode);
     Administrator a=adminService.findAllAdmins(accountNum, thecode);
     System.out.println(a);
	if(a !=null ) {
		//锟斤拷锟矫伙拷锟斤拷拥锟絪ession锟斤拷
		session.setAttribute("USER_SESSION",a);

		return  "redirect:index.jsp";
	}
	
	 //锟斤拷锟斤拷撕锟斤拷锟斤拷氩伙拷锟饺�
	model.addAttribute("msg", "锟剿号伙拷锟斤拷锟斤拷锟斤拷锟�,锟斤拷锟斤拷锟铰碉拷录");
	return "forward:/login.jsp";	
}
	/**
	 * 转锟斤拷锟斤拷Administrator.jsp 页锟斤拷
	 * */
	
	@RequestMapping("index")
	public String toAdministrator() {
		//转锟斤拷锟斤拷 Administrator.jsp页锟斤拷
		return "index";
	}
	/**
	 * 锟斤拷全锟剿筹拷
	 * */
	
	@RequestMapping("/logout")
	public String logout(HttpSession session) {
		//锟斤拷锟絪ession
		session.invalidate();
		 //锟截讹拷锟津到碉拷录页锟斤拷锟斤拷锟阶拷锟斤拷锟�
		 return "forward:houtai/login.jsp";
	}
}
